package com.reman;

import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/11/25 0025.
 */
@Component//将MyTask对象注入spring容器
@EnableScheduling//启动定时任务
public class MyTask {
    public Logger logger = Logger.getLogger(MyTask.class);
    @Scheduled(cron = "0/5 * * * * *")//通过cron表达式定义任务每5秒执行一次
    public void task(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        logger.info("定时任务:"+simpleDateFormat.format(new Date()));
    }
}
